package main

import (
	"fmt"
	"os"
)

/*
函数版学生管理系统
*/

type student struct {
	id    int64
	name  string
	class string
}

var (
	allStudents map[int64]*student
)

func add() {
	var (
		name  string
		id    int64
		class string
	)
	fmt.Println("输入姓名:")
	fmt.Scanln(&name)
	fmt.Println("输入班级:")
	fmt.Scanln(&class)
	fmt.Println("输入学号:")
	fmt.Scanln(&id)
	stu := newStudent(id, name, class)
	allStudents[id] = stu
}

func newStudent(id int64, name string, class string) *student {
	return &student{
		id,
		name,
		class,
	}
}
func show() {
	for k, v := range allStudents {
		fmt.Printf("学号%d:姓名:%s\n", k, v.name)
	}
}
func del() {
	fmt.Println("请输入要删除的学号:")
	var id int64
	fmt.Scanln(&id)
	delete(allStudents, id)
	fmt.Println("已删除")
}

func main() {
	allStudents = make(map[int64]*student, 50)
	for {
		fmt.Print("菜单！")
		fmt.Println(`
	1.查看
	2.新增
	3.删除
	4.退出
	`)

		fmt.Println("请输入：")
		var choice int
		fmt.Scanln(&choice)
		fmt.Printf("你选择：%d\n", choice)
		switch choice {
		case 1:
			show()
		case 2:
			add()
		case 3:
			del()
		case 4:
			os.Exit(1) //退出
		default:
			fmt.Println("重输：")
		}
	}
}
